package java19_4_25.com.huweilong.wait_notify;

public class Demo2 {
    static Object lock1 = new Object();
    static Object lock2 = new Object();
    static Object lock3 = new Object();

    static class MyThread extends Thread {
        @Override
        public void run() {
            synchronized (lock3) {
                System.out.println("lock3 成功");
                lock3.notify();
            }
            synchronized (lock2) {
                System.out.println("lock2 成功");
                lock2.notify();
            }
            synchronized (lock1) {
                System.out.println("lock1 成功");
                lock1.notify();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        synchronized (lock1) {
            synchronized (lock2) {
                synchronized (lock3) {
                    MyThread t = new MyThread();
                    t.start();

                    // 主线程持有 3 把锁
                    lock3.wait();   // 释放 lock3 锁
                    lock2.wait();
                    lock1.wait();
                }
            }
        }
        System.out.println("open");
    }
}
